﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DiskFlyAction : SSAction {
    public float gravity = -5;                                
    private Vector3 start_vector;                              
    private Vector3 gravity_vector = Vector3.zero;            
    private Vector3 current_angle = Vector3.zero;              
    private float time;                                      

    public static DiskFlyAction GetSSAction(int lor, float angle, float power) {
        DiskFlyAction action = CreateInstance<DiskFlyAction>();
        action.start_vector = Quaternion.Euler(new Vector3(0, 0, angle*lor))*((lor==1)?Vector3.right:Vector3.left) * power;
        return action;
    }
    public override void FixedUpdate() {}
    public override void Update() {
        // 根据时间和重力，速度的大小，算出坐标和角度，并给transform赋值
        time += Time.fixedDeltaTime;
        gravity_vector.y = gravity * time/4f;
        transform.position += (start_vector + gravity_vector) * Time.fixedDeltaTime/4f;
        current_angle.z = Mathf.Atan((start_vector.y + gravity_vector.y) / start_vector.x) * Mathf.Rad2Deg;
        transform.eulerAngles = current_angle;

        if (this.transform.position.y < -10) {
            this.destroy = true;
            this.callback.SSActionEvent(this);      
        }
    }

    public override void Start() { }
}
